package mobi.hami.huapin.dao;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.dto.NoteInfoForUserDTO;
import mobi.hami.huapin.model.NoteSchedule;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface NoteScheduleMapper extends CrudMapper<NoteSchedule> {

    /**
     * 批量修改坑号下纸条排期状态
     *
     * @param order_num 坑号
     * @param status    0 在线 1 下线
     */
    @Update("update note_schedule set status = #{status} where order_num = #{order_num}")
    int updateNoteScheduleStatusByorderNum(@Param("order_num") Integer order_num, @Param("status") Integer status);

    /**
     * 根据主键修改排期状态
     *
     * @param id     主键
     * @param status 0 在线 1下线
     */
    @Update("update note_schedule set status = #{status} where id = #{id}")
    int updateNoteScheduleStatus(@Param("id") Integer id, @Param("status") Integer status);


    /**
     * 多条件查询
     *
     * @param parms
     * @return
     */
    @SelectProvider(type = NoteScheduleProvider.class, method = "selectWitchParam")
    List<NoteSchedule> selectWitchParam(Map<String, Object> parms);

    @Select("select * from note_schedule where status=0 order by rand() LIMIT 3")
    List<NoteSchedule> FindRandLimitThree();

    /**
     * 批量插入
     *
     * @param list
     * @return
     */
    @InsertProvider(type = NoteScheduleProvider.class, method = "batchAdd")
    int batchAdd(@Param("list") List<NoteSchedule> list);

    /**
     * 获取通用纸条排期
     *
     * @return
     */
    @Select("select note_id as id,sort_id,content  from note_schedule where status = 0 and start_time < curdate() order by order_num asc ")
    List<NoteInfoForUserDTO> queryCommonNotes();

    /**
     * 删除该坑位号内没有时间的记录
     */
    @Delete("delete from note_schedule where order_num = #{order_num} and start_time is NULL")
    void deleteWithNoTimeLog(@Param("order_num") Integer order_num);


}